//
//  map.m
//  EFExtend
//
//  Created by mac on 15/6/12.
//  Copyright (c) 2015年 Eric. All rights reserved.
//

#import "map.h"


@interface map ()
@property (retain, nonatomic) MSOMapView *map;
@end

@implementation map

- (void)dealloc
{
   
    HM_SUPER_DEALLOC();
}

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
	// Do any additional setup after loading the view.
    
    [self.customNavLeftBtn setImage:[UIImage imageNamed:@"back.png"] forState:UIControlStateNormal];
    [self.customNavLeftBtn setFrame:CGRectMakeBound(32, 32)];
    
    [self.customNavRightBtn setImage:[UIImage imageNamed:@"back.png"] forState:UIControlStateNormal];
    [self.customNavRightBtn setFrame:CGRectMakeBound(32, 32)];
    
    self.map = [MSOMapView spawnInView:self.view];
    
    [[[[[UIView viewAsButten]
     EFText:@"annotion弹出框1"] EFTagString:@"123"]
     EFOwner:self.view]
     mas_makeConstraints:^(MASConstraintMaker *make) {
         make.top.mas_equalTo(self.view.mas_top).offset(10);
         make.left.mas_equalTo(self.view.mas_left).offset(10);
         make.height.mas_equalTo(40);
         make.right.mas_equalTo(self.view.mas_right).offset(-10);
     }];
    
    [[[[[UIView viewAsButten]
       EFText:@"annotion弹出框2"] EFTagString:@"12"]
      EFOwner:self.view]
     EFFrame:CGRectMake(10, 60, self.view.width-20, 40)];
    
    [HMLocationManager sharedInstance].requested = LocationRequestType_monitor;
      
}


- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

ON_Button(signal){
    UIButten *btn = signal.source;
    if ([signal is:[UIButten TOUCH_UP_INSIDE]]) {
        if ([btn is:@"leftBtn"]) {//customNavLeftBtn
            [self backAndRemoveWithAnimate:YES];
        }else if ([btn is:@"rightBtn"]){//customNavRightBtn

            [self pushToPath:URLFOR_controller(@"Search") animated:YES];
        }else if ([btn is:@"123"]){
            HMPointAnnotation *point = [[HMPointAnnotation alloc]init];
            point.coordinate = [HMLocationManager GPSLocToGoogleLoc:CLLocationCoordinate2DMake(37.469087, 109.451068)];
            point.title = @"定位时间:awerwerwerwer\n位置:陕西省榆林市横山县县道207石人坪小学东南方向810米\n速度:12km/h";
            point.tagString = @"1232342432";
            point.ID = @"0";
            point.iconId = @"back.png";
            point.data = btn.tagString;
            [self.map addAnnotation:point];
        }else if ([btn is:@"12"]){
            HMPointAnnotation *point = [[HMPointAnnotation alloc]init];
            point.coordinate = [HMLocationManager GPSLocToGoogleLoc:CLLocationCoordinate2DMake(37.479087, 109.451068)];
            point.title = @"定位时间:awerwerwerwer\n位置:陕西省榆林市横山县县道207石人坪小学东南方向810米\n速度:12km/h";
            point.tagString = @"1232342432";
            point.ID = @"0";
            point.iconId = @"back.png";
            point.data = btn.tagString;
            [self.map addAnnotation:point];
        }
    }
}

ON_MapView(signal){
    if ([signal is:[MSOMapView LOADED]]) {
        //        self.map.centerLocationFirst = YES;
        //        self.map.showsUserLocation = YES;
        
    }else if ([signal is:[MSOMapView VIEWFORANNOTATION]] ) {
        MSOAnnotationView * anView = signal.inputValue;
        if ([anView.annotation isKindOfClass:[MSOPointAnnotation class]]) {
            NSString *imageName = ((MSOPointAnnotation*)(anView.annotation)).iconId;
            UIImage *image = [UIImage imageNamed:imageName];
            [anView setCalloutViewUserInterface:YES];
            anView.canShowCallout  = YES;
            anView.image = image;
            anView.remark.text = ((MSOPointAnnotation*)(anView.annotation)).tagString;
            anView.clipsToBounds = NO;
            
        }
        
    }else if ([signal is:[MSOMapView ANNOVIEWRELOAD]] ) {
        
    }else if ([signal is:[MSOMapView SELECTANNOTATIONVIEW]]){
        MSOAnnotationView *pointV= signal.inputValue;
        
    }else if ([signal is:[MSOMapView VIEWFORCALLOUT]] ) {
        
        HMMapCalloutView *cell = [HMMapCalloutView spawnWithType:CALLOUTVIEWTYPE_SUBTITLEFULL];
        cell.clipsToBounds = YES;
        MSOAnnotationView *pointV= signal.inputValue;
        
        //        cell.title.numberOfLines = 1;
        cell.title.text = ((MSOPointAnnotation*)(pointV.annotation)).title;
        cell.subtitle.text = ((MSOPointAnnotation*)(pointV.annotation)).subtitle;
        cell.title.textColor = RGB(130, 130, 130);
        cell.subtitle.textColor = RGB(198, 138, 74);
        
        if ([((MSOPointAnnotation*)(pointV.annotation)).data isEqual:@"123"]) {
            [cell resetView];
        }
        
        signal.returnValue = cell;
    }else if([signal is:[MSOMapView VIEWFORCALLOUTRESET]]){
        MSOAnnotationView *pointV= signal.inputValue;
        if ([((MSOPointAnnotation*)(pointV.annotation)).data isEqual:@"12"]) {
            [pointV.calloutViewCell mas_makeConstraints:^(MASConstraintMaker *make) {
                make.top.mas_equalTo(10);
                make.left.mas_equalTo(8);
                make.height.mas_equalTo(40);
                make.width.mas_equalTo(100);
            }];
        }

        
    }else if ([signal is:[MSOMapView VIEWFOROVERLAY]]){
        
        MSOPolylineView *polylineView = (id)signal.inputValue;
        polylineView.strokeColor = RGB(125, 188, 16);
        
    }
    
}


@end
